package com.example.helloredis.jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.resps.Tuple;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName: JedisConnector
 * @Description:
 * @Author: 12071
 * @Date: 2022/6/22 18:07
 */
public class JedisConnection {

    public static void main(String[] args) {
        JedisPool pool = new JedisPool("localhost", 6397, null, "redisWSL998-");
        try (Jedis jedis = pool.getResource()) {
            System.out.println(jedis.ping());

            Set<String> keys = jedis.keys("*");
            System.out.println(keys);

            // String
            String str = jedis.get("str");
            System.out.println(str);

            // List
            List<String> list = jedis.lrange("list",0,10);
            System.out.println(list);

            // Hash
            Map<String, String> map = jedis.hgetAll("map");
            System.out.println(map);

            // Set
            Set<String> set = jedis.smembers("set");
            System.out.println(set);

            // sortedSet
            List<Tuple> zset = jedis.zrangeWithScores("zset", 0, 5);
            System.out.println(zset);
        }
    }
}
